#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#include <sys/wait.h>

void Reader(int rfd)
{
    char str[1024];
    while(1)
    {
        ssize_t n = read(rfd, str, sizeof(str) - 1);
        printf("child get message : %s\n", str);
    }
}

void Writer(int wfd)
{
    while(1)
    {
        char str[1024];
        scanf("%s", str);
        write(wfd, str, sizeof(str) - 1);
    }
}

int main()
{
    int pipefd[2];
    int n = pipe(pipefd);
    if(n < 0)   return 1;
    pid_t id = fork();
    if(id == 0)
    {
        close(pipefd[1]);
        Reader(pipefd[0]);

        exit(0);
    }
    close(pipefd[0]);
    Writer(pipefd[1]);

    wait(NULL);

    return 0;
}